<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="Bookmark" href="/favicon.ico" >
    <link rel="Shortcut Icon" href="/favicon.ico" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="/static/lib/html5shiv.js"></script>
    <script type="text/javascript" src="/static/lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="/static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="/static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="/static/lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="/static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="/static/h-ui.admin/css/style.css" />
    <!--    <link rel="stylesheet" href="../../../css/demo.css" type="text/css">-->
    <link rel="stylesheet" href="/static/lib/zTree/v3/css/metroStyle/metroStyle.css" type="text/css">
    <!--[if IE 6]>
    <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>角色设置权限</title>

</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 后台用户 <span class="c-gray en">&gt;</span> 角色管理 <span class="c-gray en">&gt;</span> 设置权限   <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">

    <div id="treeDemo" class="ztree"></div>
    <div>
        <hr>
        <input type="hidden" id="role_id" value="{$role_id}">
        <p class="pt-5"><a href="javascript:;" onclick="save()" class="btn btn-primary">保存</a></p>
    </div>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="/static/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="/static/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="/static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="/static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/static/lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="/static/lib/zTree/v3/js/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript" src="/static/lib/zTree/v3/js/jquery.ztree.excheck-3.5.js"></script>
{literal}
<SCRIPT type="text/javascript">
    var setting = {
        check: {
            enable: true
        },
        data: {
            simpleData: {
                enable: true
            }
        }
    };

    var zNodes = <?php echo $nodes; ?>;

    function disabledNode(e) {
        var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
            disabled = e.data.disabled,
            nodes = zTree.getSelectedNodes(),
            inheritParent = false, inheritChildren = false;
        if (nodes.length == 0) {
            alert("请先选择一个节点");
        }
        if (disabled) {
            inheritParent = $("#py").attr("checked");
            inheritChildren = $("#sy").attr("checked");
        } else {
            inheritParent = $("#pn").attr("checked");
            inheritChildren = $("#sn").attr("checked");
        }

        for (var i=0, l=nodes.length; i<l; i++) {
            zTree.setChkDisabled(nodes[i], disabled, inheritParent, inheritChildren);
        }
    }

    $(document).ready(function(){
        $.fn.zTree.init($("#treeDemo"), setting, zNodes);
        $("#disabledTrue").bind("click", {disabled: true}, disabledNode);
        $("#disabledFalse").bind("click", {disabled: false}, disabledNode);
    });


    function save() {

        var role_id = $('#role_id').val();
        var zTree = $.fn.zTree.getZTreeObj("treeDemo");
        var checkedNodes = zTree.getCheckedNodes();
        var ids = "";
        for(var i=0;i<checkedNodes.length;i++){
            ids += checkedNodes[i].id + ",";
        }

        var uri = '/admin/Role/setRolePermission';

        $.post(uri,{role_id:role_id,ids:ids},function (res) {
            if(res.err>0){
                layer.msg(res.msg, {icon: 2});

            } else {

                layer.msg(res.msg, {icon: 1});
            }
            return true;
        });

    }

</SCRIPT>
{/literal}
</body>
</html>